package com.xy.redisson.config;

import com.xy.redisson.RedissonLock;
import com.xy.redisson.RedissonManager;
import com.xy.redisson.properties.RedissonProperties;
import lombok.extern.slf4j.Slf4j;
import org.redisson.Redisson;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;

/**
 * @author xxy
 * @date 2022/1/5 20:34
 */
@Slf4j
@Configuration
@ConditionalOnClass(Redisson.class)
@EnableConfigurationProperties(RedissonProperties.class)
public class RedissonAutoConfiguration {


    @Bean
    @ConditionalOnMissingBean
    @Order(1)
    public RedissonManager redissonManager(RedissonProperties redissonProperties) {
        log.info("[RedissonManager]组装完毕,当前连接方式:" + redissonProperties.getType() +
                ",连接地址:" + redissonProperties.getAddress());
        return new RedissonManager(redissonProperties);
    }


    @Bean
    @ConditionalOnMissingBean
    @Order(2)
    public RedissonLock redissonLock(RedissonManager redissonManager) {
        log.info("[RedissonLock]组装完毕");
        return new RedissonLock(redissonManager);
    }


}
